package com.ph.irp.base.assistantmaterial.action;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.ph.irp.base.assistantmaterial.service.PBaseAssistantmaterialCustomerTypeService;
import com.ph.irp.model.PBaseAssistantmaterialCustomercategory;

public class AssistantmaterialCustomerTypeAction extends ActionSupport {

	private static final long serialVersionUID = 4764377778075548073L;

	// 领料用途service
	private PBaseAssistantmaterialCustomerTypeService customerTypeService;
	// 领料用途list
	private List<PBaseAssistantmaterialCustomercategory> customerTypeList;
	// 领料用途model
	private PBaseAssistantmaterialCustomercategory customerTypeModel;
	// 接收选中复选框传递的数据
	private String[] rowlist = null;
	private String FORWARD;

	/**
	 * 动态查询客户类型
	 * 
	 * @return
	 */
	public String getCustomerTypes() throws Throwable {
		if (customerTypeModel == null)
			customerTypeList = customerTypeService.getAllCustomerTypes();
		else if (!customerTypeModel.getCustomerCategoryCode().trim().equals("")
				&& !customerTypeModel.getCustomerCategoryName().trim().equals(
						""))
			customerTypeList = customerTypeService
					.getCustomerTypesByCodeAndName(customerTypeModel
							.getCustomerCategoryCode(), customerTypeModel
							.getCustomerCategoryName());
		else if (!customerTypeModel.getCustomerCategoryCode().trim().equals(""))
			customerTypeList = customerTypeService
					.getCustomerTypesByCode(customerTypeModel
							.getCustomerCategoryCode());
		else if (!customerTypeModel.getCustomerCategoryName().trim().equals(""))
			customerTypeList = customerTypeService
					.getCustomerTypesByName(customerTypeModel
							.getCustomerCategoryName());
		else
			customerTypeList = customerTypeService.getAllCustomerTypes();
		customerTypeModel = null;
		FORWARD = "success";
		return FORWARD;
	}

	/**
	 * 增加辅助物料客户类型
	 * 
	 * @param
	 * @return
	 */
	public String addCustomerType() throws Throwable {
		customerTypeService.addCustomerType(customerTypeModel);
		customerTypeModel = null;
		FORWARD = "success";
		return FORWARD;
	}
	
	/**
	 * 修改辅助物料客户类型
	 * 
	 * @param
	 * @return
	 */
	public String updateCustomerType() throws Throwable {
		customerTypeService.updateCustomerType(customerTypeModel);
		customerTypeModel = null;
		FORWARD = "success";
		return FORWARD;
	}


	/**
	 * 修改辅助物料客户类型,跳转到修改页面
	 * 
	 * @return
	 */
	public String updateCustomerTypeInput() throws Throwable {
		// 要更新的客户类别的id
		int customerTypeId = Integer.valueOf((String) rowlist[0]);
		// 要更新的客户类型的model
		customerTypeModel = customerTypeService
				.getCustomerTypeById(customerTypeId);
		// 跳转到更新页面
		FORWARD = "success";
		return FORWARD;
	}

	/**
	 * 删除辅助物料客户类型
	 * 
	 * @return
	 */
	public String deleteCustomerType() throws Throwable {

		// 批量删除客户类别
		customerTypeService.deleteProductpurposeById(rowlist);
		customerTypeModel = null;
		FORWARD = "success";
		return FORWARD;
	}

	/**
	 * 选择辅助物料客户类型
	 * 
	 * @return
	 * @throws Throwable
	 */
	public String selectCustomerType() throws Throwable {

		this.getCustomerTypes();
		customerTypeModel = null;
		FORWARD = "success";
		return FORWARD;
	}
	
	public String showCustomerTypeList() throws Throwable {
		customerTypeModel = null;
		this.getCustomerTypes();
		FORWARD ="success";
		return FORWARD;
	}

	/**
	 * setters and getters for instance variables
	 * 
	 * @return
	 */

	public PBaseAssistantmaterialCustomerTypeService getCustomerTypeService() {
		return customerTypeService;
	}

	public void setCustomerTypeService(
			PBaseAssistantmaterialCustomerTypeService customerTypeService) {
		this.customerTypeService = customerTypeService;
	}

	public List<PBaseAssistantmaterialCustomercategory> getCustomerTypeList() {
		return customerTypeList;
	}

	public void setCustomerTypeList(
			List<PBaseAssistantmaterialCustomercategory> customerTypeList) {
		this.customerTypeList = customerTypeList;
	}

	public PBaseAssistantmaterialCustomercategory getCustomerTypeModel() {
		return customerTypeModel;
	}

	public void setCustomerTypeModel(
			PBaseAssistantmaterialCustomercategory customerTypeModel) {
		this.customerTypeModel = customerTypeModel;
	}

	public String[] getRowlist() {
		return rowlist;
	}

	public void setRowlist(String[] rowlist) {
		this.rowlist = rowlist;
	}

}
